<template>
	<div class="personnelAdd">
		<el-breadcrumb separator="/">
			<el-breadcrumb-item :to="{ path: '/' }">
				<i class="lh lh-caiwu fw_100"></i>
			</el-breadcrumb-item>
			<el-breadcrumb-item>人才结算管理</el-breadcrumb-item>
			<el-breadcrumb-item>编辑结算通道</el-breadcrumb-item>
		</el-breadcrumb>
		<div class="content_Box box-shadow mt_15 px_10">
			<el-tabs type="border-card">
				<el-tab-pane label="编辑结算通道">
					<el-form label-width="120px" class="mw_400">
						<el-form-item label="结算通道名称">
							<el-input v-model="dataMes.name"></el-input>
						</el-form-item>
						<el-form-item label="签约公司">
							<el-input v-model="dataMes.company_name"></el-input>
						</el-form-item>
						<el-form-item label="分行/支行">
							<el-input v-model="dataMes.company_bank_name"></el-input>
						</el-form-item>
						<el-form-item label="账号">
							<el-input v-model="dataMes.company_bank_card"></el-input>
						</el-form-item>
						<el-form-item label="税源地名称">
							<el-input v-model="dataMes.tax_source"></el-input>
						</el-form-item>
						<el-form-item label="税源地支行">
							<el-input v-model="dataMes.bank_name"></el-input>
						</el-form-item>
						<el-form-item label="账号">
							<el-input v-model="dataMes.bank_card"></el-input>
						</el-form-item>
						<el-form-item label="签约日期" :required="true">
							<el-date-picker
								v-model="dataMes.sign_date_start"
								value-format="yyyy-MM-dd"
								type="date"
								placeholder="选择日期"
							>
							</el-date-picker>
						</el-form-item>
						<el-form-item label="终止日期" :required="true">
							<el-date-picker
								v-model="dataMes.sign_date_end"
								value-format="yyyy-MM-dd"
								type="date"
								placeholder="选择日期"
							>
							</el-date-picker>
						</el-form-item>
						<el-form-item label="签约费率（%）" :required="true">
							<el-input v-model="dataMes.rate" class="w_80"></el-input>
						</el-form-item>
						<el-form-item label="类型" :required="true">
							<el-select v-model="dataMes.type">
								<el-option label="平台" value="1"></el-option>
								<el-option label="三方" value="2"></el-option>
							</el-select>
						</el-form-item>
						<el-form-item class="my_20">
							<el-button round @click="back">返回</el-button>
							<el-button round type="primary" @click="submitBtn">提交</el-button>
						</el-form-item>
					</el-form>
				</el-tab-pane>
			</el-tabs>
		</div>
	</div>
</template>

<script>
import { fetchtlementInfo, fetchtlementSetInfo } from '@/api/talent.js'
export default {
	name: 'ChannelEdit',
	data() {
		return {
			//相关数据
			dataMes: {
				name: '',
				company_name: '',
				company_bank_name: '',
				company_bank_card: '',
				tax_source: '',
				bank_name: '',
				bank_card: '',
				sign_date_start: '',
				sign_date_end: '',
				rate: '',
				type: ''
			}
		}
	},
	created() {
		if (this.$route.query.sn) {
			// 获取结算通道详情
			this.getChanneInfo()
		}
	},
	methods: {
		async submitBtn() {
			// 新增接口
			if (!this.dataMes.sign_date_start || !this.dataMes.sign_date_end || !this.dataMes.rate || !this.dataMes.type) {
				this.$message.error('请填写必填项')
				return
			}

			if (isNaN(+this.dataMes.rate) || +this.dataMes.rate < 0) {
				this.$message.error('签约费率不符合规范！')
				return
			}

			let ret = await fetchtlementSetInfo({
				sn: this.$route.query.sn,
				...this.dataMes
			})

			this.$message.success('操作成功！')
			this.back()
		},
		async getChanneInfo() {
			try {
				let ret = await fetchtlementInfo({
					sn: this.$route.query.sn
				})

				for (let key in this.dataMes) {
					for (let it in ret) {
						if (key == it) this.dataMes[key] = ret[it]
						//单独处理
						this.dataMes['type'] = '' + ret['type']
						this.dataMes['rate'] = ret['rate'] * 100
					}
				}
			} catch (err) {}
		},
		back() {
			//返回
			this.$router.go(-1)
		}
	}
}
</script>

<style scoped>
.row-info {
	margin-bottom: 10px;
}
.title-key {
	width: 100px;
}
.list-cont img {
	width: 128px;
}
</style>



// WEBPACK FOOTER //
// src/components/talentSettlement/ChannelEdit.vue